package org.sction.support.spring;

import java.util.Set;

import org.apache.log4j.Logger;
import org.sction.bean.listener.BeanListener;
import org.sction.cache.CacheManager;
import org.sction.util.ClassPathScanHandler;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;


public class SpringApplicationListener implements ApplicationListener {
	private static final Logger logger = Logger.getLogger(BeanListener.class);
	private String scanningPath = ".";

	 

	public String getScanningPath() {
		return scanningPath;
	}



	public void setScanningPath(String scanningPath) {
		this.scanningPath = scanningPath;
	}



	public void onApplicationEvent(ApplicationEvent event) {
		ClassPathScanHandler handler = new ClassPathScanHandler();
		String[] scanningPaths = scanningPath.split(",");
		for (String packagepath : scanningPaths) {
			logger.info("Scanning path :" + packagepath);
			Set<Class<?>> classes = handler.getPackageAllClasses(packagepath,
					true);
			for (Class<?> clazz : classes) {
				CacheManager.putAction(clazz);
			}
		}
	}

}
